Make dom0_enforce_cpus() use vcpu_hotplug rather than directly modifying the sysfs...
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Fri, 16 Sep 2005 19:08:36 +0000 (19:08 +0000)
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Fri, 16 Sep 2005 19:08:36 +0000 (19:08 +0000)
Directly modifying the sysfs entries causes the xenstore state of
a cpu's availability to be incorrect.  Also slightly modify the
dom0-cpus description in the xend-config.  Rather than specifying which
dom0 vcpus are to be used, it is now a target of how many vcpus to use
as pinvcpu ops are the preferred method for setting which physical cpu a
vcpu uses.
Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
tools/examples/xend-config.sxp
tools/python/xen/xend/XendDomain.py
tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xend/server/SrvDaemon.py

index 249cdce507aa3ad5249785b8954f3b1d54085d74..1b6b8c52e1ec7a06047a852ed5e87c9b5c92f435 100644 (file)
@@ -49,6 +49,6 @@
 # If dom0-min-mem=0, dom0 will never balloon out.
 (dom0-min-mem 0)
 
-# In SMP system, dom0 will use only CPUs in range [1,dom0-cpus]
+# In SMP system, dom0 will use dom0-cpus # of CPUS
 # If dom0-cpus = 0, dom0 will take all cpus available
 (dom0-cpus 0)
index 6842be0e5237fd205ef4edeed943549f317a8dc6..ba588146eaccdba2b4b29b31311b867768cef0bb 100644 (file)
@@ -155,6 +155,7 @@ class XendDomain:
         if not dom0:
             dom0 = self.domain_unknown(0)
         dom0.dom0_init_store()    
+        dom0.dom0_enforce_cpus()
 
     def close(self):
         pass
index 1c89862ae21062697d65f5c1d545e610fe407a76..40f822afd89bc034d3992882d80540a498d486c5 100644 (file)
@@ -1120,6 +1120,26 @@ class XendDomainInfo:
             # get run-time value of vcpus and update store
             self.configure_vcpus(dom_get(self.domid)['vcpus'])
 
+    def dom0_enforce_cpus(self):
+        dom = 0
+        # get max number of cpus to use for dom0 from config
+        from xen.xend import XendRoot
+        xroot = XendRoot.instance()
+        target = int(xroot.get_dom0_cpus())
+        log.debug("number of cpus to use is %d" % (target))
+   
+        # target = 0 means use all processors
+        if target > 0:
+            # count the number of online vcpus (cpu values in v2c map >= 0)
+            vcpu_to_cpu = dom_get(dom)['vcpu_to_cpu']
+            vcpus_online = len(filter(lambda x: x >= 0, vcpu_to_cpu))
+            log.debug("found %d vcpus online" % (vcpus_online))
+
+            # disable any extra vcpus that are online over the requested target
+            for vcpu in range(target, vcpus_online):
+                log.info("enforcement is disabling DOM%d VCPU%d" % (dom, vcpu))
+                self.vcpu_hotplug(vcpu, 0)
+
 
 def vm_field_ignore(_, _1, _2, _3):
     """Dummy config field handler used for fields with built-in handling.
index 378497e5574973b52b1e085e6a87e4fc00258250..df32b577a9ff142b877d16129bc3c369991b45a8 100644 (file)
@@ -298,7 +298,6 @@ class Daemon:
         return self.cleanup(kill=True)
 
     def run(self, status):
-        _enforce_dom0_cpus()
         try:
             log.info("Xend Daemon started")
             event.listenEvent(self)
@@ -323,32 +322,6 @@ class Daemon:
         #sys.exit(rc)
         os._exit(rc)
 
-def _enforce_dom0_cpus():
-    dn = xroot.get_dom0_cpus()
-
-    for d in glob.glob("/sys/devices/system/cpu/cpu*"):
-        cpu = int(os.path.basename(d)[3:])
-        if (dn == 0) or (cpu < dn):
-            v = "1"
-        else:
-            v = "0"
-        try:
-            f = open("%s/online" %d, "r+")
-            c = f.read(1)
-            if (c != v):
-                if v == "0":
-                    log.info("dom0 is trying to give back cpu %d", cpu)
-                else:
-                    log.info("dom0 is trying to take cpu %d", cpu)
-                f.seek(0)
-                f.write(v)
-                f.close()
-                log.info("dom0 successfully enforced cpu %d", cpu)
-            else:
-                f.close()
-        except:
-            pass
-
 def instance():
     global inst
     try: